package madixin.t241;

import java.util.LinkedList;
import java.util.List;

class Solution {
    public List<Integer> diffWaysToCompute(String input) {
        List<Integer> res = new LinkedList<>();
        if (input == null) {
            return res;
        }

        for (int i = 0; i < input.length(); i++) {
            char oper = input.charAt(i);
            if (oper == '+' || oper == '-' || oper == '*') {
                List<Integer> left = diffWaysToCompute(input.substring(0, i));
                List<Integer> right = diffWaysToCompute(input.substring(i + 1));
                for (Integer l : left) {
                    for (Integer r : right) {
                        switch (oper) {
                            case '+': {
                                res.add(l + r);
                                break;
                            }
                            case '-': {
                                res.add(l - r);
                                break;
                            }
                            case '*': {
                                res.add(l * r);
                                break;
                            }
                        }
                    }
                }
            }
        }

        if (res.size() == 0) {
            res.add(Integer.parseInt(input));
        }
        return res;
    }

    public static void main(String[] args) {
        Solution s = new Solution();
        List<Integer> res = s.diffWaysToCompute("2*3-4*5");
        System.out.println(res);

    }


}
